{extend name="common/application" /}
{block name="title"}<title id="title">店铺中心-资料设置</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/help.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/store_center.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
<style>
.install-box .pub-right .img-logo img{border-radius:0;}
</style>
{/block}

{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix">
        <!--左菜单-->
        {include file="/common/left" /}
        <!--右内容-->
        <div class="menuContent fr">
            <div class="menuConHeader">
                <!--面包屑导航-->
                <div class="breadcrumb">
                    <p>
                        <a href="javascript:;">店铺管理</a> &gt;
                        <a class="curPage" href="{:url('index/store/install')}">店铺资料设置</a>
                    </p>
                </div>
            </div>
            <div class="menuConBody">
                <div class="courseMenu">
                    <div class="conBody">
                        <div class="publist-box install-box">
                            <form id="form-admin-add">
                                <div class="row">
                                    <label class="pub-left">店铺类型:</label>
                                    <div class="pub-right">
                                        <p class="install"></p>
                                    </div>
                                </div>
                                <input type="hidden" id="span" name="label">
                                <input type="hidden" id="id" name="id" value="">
                                <div class="row">
                                    <label class="pub-left">店铺招牌:</label>
                                    <div class="pub-right">
                                        <div class="img-logo" id="img-logo">
                                            <img class="install" src="_IMG_/store.jpg">
                                        </div>
										<input type="hidden" id="image" name="image">
                                        <div class="upimg">
                                            <p>点击上传店铺招牌</p>
                                            <input type="file" name="img" id="upload-logo"
                                                   onchange="previewImage(this,2)"
                                                   accept="image/gif, image/jpeg, image/png" title="点击选择图片">
                                        </div>
                                        <div class="tip-box">
                                            <p>注：仅仅支持JPG、PNG、JPEG格式，文件小于4M</p>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left">店铺名称:</label>
                                    <div class="pub-right">
                                        <input type="text" class="install" name="name" placeholder="" value="">
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left">邮箱:</label>
                                    <div class="pub-right">
                                        <p class="revise-box install"></p>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left">手机号码:</label>
                                    <div class="pub-right">
                                        <!-- 修改跳转到个人中心-信息安全页面 -->
                                        <p class="revise-box install"></p>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left">店铺标签:</label>
                                    <div class="pub-right">
                                        <p class="tag-box">
                                            <!--<span all="1">行政诉讼</span>-->
                                            <!--<span all="2">专利代理</span>-->
                                            <!--<span all="3">政策应用</span>-->
                                            <!--<span all="4">设计开发</span>-->
                                            <!--<span all="5">专利托管</span>-->
                                            <!--<span all="6">专利评议</span>-->
                                            <!--<span all="7">专利维权</span>-->
                                            <!--<span all="8">设计开发</span>-->
                                        </p>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left">经验范围:</label>
                                    <div class="pub-right">
                                        <textarea class="install" name="scope"></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left">服务宗旨:</label>
                                    <div class="pub-right">
                                        <textarea class="install" name="tenet"></textarea>
                                    </div>
                                </div>
                                <div class="row">
                                    <label class="pub-left"></label>
                                    <div class="pub-right">
                                        <a class="publish-btn" href="javascript:;">提交</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>

<script>
    $(document).ready(function () {
        $('.li0').addClass('showChild');
        $('.li01').addClass('activeMenu');
    });

    /* 图片上传*/
    function previewImage(obj) {
        var filepath = $(obj).val();
        fileObj = document.getElementById('upload-logo');
        value = window.URL.createObjectURL(fileObj.files[0]);
        file_size = obj.files[0].size;
        size = file_size / 1024;
        if (size > 1024 * 4) {
            $('#file' + num).val("");
            layer.alert('上传图片不得大于4MB', {
                closeBtn: 0
            });
        } else {
            $('#img-logo img').attr("src", value);
        }
    }

    $(function () {
        postfile();
    });

    function postfile() {
        var userinfo = $.cookie('userinfo');
        if (userinfo != null) {
            var user_login = $.base64.decode(userinfo).split(",");
            var span = $("#span").val();
            $.ajax({
                type: "get",
                url: "{:url('api/shop/install')}",
                data: {'uid': user_login[0]},
                dataType: 'jsonp',
                success: function (msg) {
                    if (msg.code == 200) {
                        $("#id").val(msg.data.id);
                        $(".install").eq(0).text(msg.data.shop_name);
                        if (msg.data.image == null) {
                            $(".install").eq(1).attr('src', "/static/web/images/store.jpg");
							$("#image").val("store.jpg");
                        } else {
                            $(".install").eq(1).attr('src', "/Images/Information/" + msg.data.image);
							$("#image").val(msg.data.image);
                        }
                        $(".install").eq(2).val(msg.data.name);
                        $(".install").eq(3).html(msg.data.email + "<a href='/index.php/index/person/account.html'>修改</a>");
						if(msg.data.phone != null){
							$(".install").eq(4).html(msg.data.phone + "<a href='/index.php/index/person/account.html'>修改</a>");
						}else{
							$(".install").eq(4).html("暂无<a href='/index.php/index/person/account.html'>修改</a>");
						}
                        $(".install").eq(5).text(msg.data.scope);
                        $(".install").eq(6).text(msg.data.tenet);
                        if (msg.data.label_shop.length > 0) {
                            for (var i = 0; i < msg.data.label_shop.length; i++) {
                                if ($.inArray(msg.data.label_shop[i].id + '', msg.data.label) != -1) {
                                    var html = '<span class="check-span" all="' + msg.data.label_shop[i].id + '">' + msg.data.label_shop[i].name + '</span>';

                                } else {
                                    html = '<span all="' + msg.data.label_shop[i].id + '">' + msg.data.label_shop[i].name + '</span>';
                                }
                                var arrs = new Array();
                                $("p.tag-box span[class='check-span']").each(function () {
                                    arrs.push($(this).attr('all'));
                                });
                                var all = arrs.join(",");
                                $("#span").val(all);
                                $('p.tag-box').append(html);
                            }
                            /*标签选择*/
                            $(document).ready(function () {
                                /*标签选择*/
                                $('p.tag-box span').on('click', function () {
                                    $(this).toggleClass('check-span');
                                    var arrs = new Array();
                                    $("p.tag-box span[class='check-span']").each(function () {
                                        arrs.push($(this).attr('all'));
                                    });
                                    var all = arrs.join(",");
                                    $("#span").val(all);
                                })
                            });
                        }

                    } else {
                        layer.msg(msg.message, {icon: 5, time: 5000});
                    }
                }
            })
        } else {
            window.location.href = "{:url('index/login/index')}";
        }
    }

    // $("form").ajax({
    //     type: "post",
    //     url: "{:url('api/shop/install_add')}",
    //     dataType: 'json',
    //     success: function (msg) {
    //         if (msg.code == 200) {
    //
    //         } else {
    //             layer.msg(msg.message, {icon: 5, time: 5000});
    //         }
    //     }
    // });

    $(".publish-btn").click(function () {
         var id = $("#id").val();
        // var image = $(".install").eq(1).attr('src');
        // var name = $(".install").eq(2).val();
        // var scope = $(".install").eq(5).val();
        // var tenet = $(".install").eq(6).val();

        //body.find("#user_id").val(user_uid);
        var formData = new FormData($('form')[0]);
		formData.append('id', id);
        // return false;
        $.ajax({
            type: "post",
            url: "{:url('api/shop/install_add')}",
            data: formData,
            dataType: 'json',
			beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
			},
            success: function (msg) {
                layer.closeAll();
                if (msg.code == 200) {
					layer.msg(msg.message, {icon: 1, time: 3000},function(){
						window.location.href = "{:url('index/store/index')}"
					});
                } else {
                    layer.msg(msg.message, {icon: 5, time: 5000});
                }
            },
            contentType: false, //必须false才会自动加上正确的Content-Type
            processData: false //必须false才会避开jQuery对 formdata 的默认处理
        })
    });


</script>
{/block}
